#生成括号
from typing import List

class Solution:
    def generateParenthesis(self, n: int) -> List[str]:
        """
        生成所有有效的括号组合
        """
        result = []

        def backtrack(open_count, close_count, path):
            # 如果左右括号都用完，加入结果
            if open_count == n and close_count == n:
                result.append(path)
                return
            # 若还能添加左括号
            if open_count < n:
                backtrack(open_count + 1, close_count, path + "(")
            # 若左括号多于右括号，添加右括号
            if close_count < open_count:
                backtrack(open_count, close_count + 1, path + ")")

        backtrack(0, 0, "")
        return result


# 示例调用
if __name__ == "__main__":
    param_1 = 3  # 你可以修改参数测试不同情况
    solution = Solution()
    ret = solution.generateParenthesis(param_1)
    print(ret)
